package com.ddc.study.feature.query;

import com.ddc.study.entity.History;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.paging.DataSource;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

/**
 * Created on 2019/11/16.
 *
 * @author lshun
 * @version 1.0
 */
@Dao
public interface HistoryDao {
    @Insert
    long addHistory(@NonNull History history);

    @Delete
    void deleteHistory(@NonNull History history);

    @Update
    void updateHistory(@NonNull History history);

    @Nullable
    @Query("SELECT * FROM History WHERE searchWord = :searchWord ORDER BY dbId ASC limit 0,1")
    History getHistoryBySearchWord(@NonNull String searchWord);

    @Query("SELECT * FROM History ORDER BY dbId ASC")
    DataSource.Factory<Integer, History> getAllData();
}
